<template>
  <a-modal v-model:visible.sync="store.state.user.add_status" title="字典类型新增" @ok="handleOk" okText="确认" cancelText="取消"
           @cancel="handle_cancel">
    <div class="row_box">
      <div class="column_box">
        <span>编码</span>
        <a-input v-model:value="formState.params.code" placeholder="请输入编码"/>
      </div>
      <div class="column_box">
        <span>名称</span>
        <a-input v-model:value="formState.params.name" placeholder="请输入名称"/>
      </div>
      <div class="column_box">
        <span>排序</span>
<!--        <a-input v-model:value="formState.params.sort" placeholder="请输入排序"/>-->
        <a-select
            placeholder="请选择排序"
            v-model:value="formState.params.sort"
            style="width: 100%"
            ref="select"
        >
          <a-select-option :value="0">倒序</a-select-option>
          <a-select-option :value="1">顺序</a-select-option>
        </a-select>
      </div>
      <div class="column_box">
        <span>状态</span>
<!--        <a-input v-model:value="formState.params.status" placeholder="请输入状态"/>-->
        <a-select
            placeholder="请选择状态"
            v-model:value="formState.params.status"
            style="width: 100%"
            ref="select"
        >
          <a-select-option :value="0">停止</a-select-option>
          <a-select-option :value="1">启用</a-select-option>
        </a-select>
      </div>
      <div class="column_box">
        <span>备注</span>
        <a-input v-model:value="formState.params.remark" placeholder="请输入备注"/>
      </div>
    </div>
  </a-modal>
</template>

<script>
import {defineComponent, reactive} from "vue";
import {useStore} from "vuex"
import {edit_dic_type} from "@/api/dic/type"
import {message} from "ant-design-vue";

export default defineComponent({
  name: "dic_type_add",
  setup(props,context) {
    const formState = reactive({
      params: {
        "typeId": 0,
        "name": "",
        "code": "",
        "sort": null,
        "remark": "",
        "status": null,
        "createTime": "",
        "updateTime": "",
        "createUserId": "",
        "updateUserId": ""
      }
    })

    /**
     * 状态管理
     *
     * */
    const store = useStore()

    /**
     * 确认新增
     *
     * */
    const handleOk = async () => {
      store.commit("SET_ADD_ROLE", false)

      const res = await edit_dic_type(formState.params)
      console.log(res)
      if (res.code === 1) {
        message.success("新增成功")
        context.emit("re_flash:re_flash","")
        return
      }
      message.success(res.message)

    }

    /**
     * 取消
     * */
    const handle_cancel = () => {
      store.commit("SET_ADD_ROLE", false)
    }

    return {
      formState,
      //状态管理
      store,
      // methods
      handleOk,
      handle_cancel
    }
  }
})
</script>

<style scoped lang="scss">

</style>
